//
//  BaseViewController.m
//  Fruit
//
//  Created by ༺ོ࿆飞༻ on 2020/2/2.
//  Copyright © 2020 ༺ོ࿆飞༻. All rights reserved.
//

#import "BaseViewController.h"


@interface BaseViewController ()

@end

@implementation BaseViewController
/**前往设置主题**/
- (void )pushToSkinSettingViewController{
//    SkinsListViewController *vc = [SkinsListViewController new];
//    [self.navigationController pushViewController:vc animated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kWhiteColor;
    [self startMonitoringNetwork];
    
    // 表示本类支持旋转
    [UIViewController attemptRotationToDeviceOrientation];

}
#pragma mark -- 监听网络
- (void )startMonitoringNetwork{
    if ([NSStringFromClass(self.class) isEqualToString:@"MainViewController"]) {
        AFNetworkReachabilityManager * manager = [AFNetworkReachabilityManager sharedManager];
        [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
               /*
                AFNetworkReachabilityStatusUnknown          = -1,
                AFNetworkReachabilityStatusNotReachable     = 0,
                AFNetworkReachabilityStatusReachableViaWWAN = 1,
                AFNetworkReachabilityStatusReachableViaWiFi = 2,
                */
               switch (status) {
                   case AFNetworkReachabilityStatusUnknown:
                       WALog(@"AFNetwork Reachability Status Unknown");
                       break;
                    case AFNetworkReachabilityStatusNotReachable:
                       WALog(@"AFNetwork Reachability Status Not Reachable");
                       [LLUtils showAlterView:self title:@"network_abnormal" message:@"" yesBtnTitle:@"confirm" noBtnTitle:@"cancel" yesBlock:^{
                           [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
                       } noBlock:^{
                           
                       }];
                       
                       break;
                   case  AFNetworkReachabilityStatusReachableViaWWAN:
                       WALog(@"AFNetwork Reachability Status Reachable ViaWWAN 3G|4G ");
                       break;
                   case AFNetworkReachabilityStatusReachableViaWiFi:
                       WALog(@"AFNetwork Reachability Status Reachable ViaWWAN");
                       break;
                   default:
                       break;
               }
           }];
         [manager startMonitoring];
    }
}

-(CGFloat)statusBarHight {
    float statusBarHeight = 0;
    if (@available(iOS 13.0, *)) {
        UIStatusBarManager *statusBarManager = [UIApplication sharedApplication].windows.firstObject.windowScene.statusBarManager;
        statusBarHeight = statusBarManager.statusBarFrame.size.height;
    }
    else {
        statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
    }
    return statusBarHeight;
}

- (void)setNavTitleStr:(NSString *)navTitleStr
{
    _navTitleStr = navTitleStr;
    self.navigationItem.title = navTitleStr;
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : RGB(0, 0, 0),
    NSFontAttributeName : FONT(18)}];
    [self.navigationController.navigationBar setBackIndicatorImage:[UIImage imageNamed:@"nav_back_icon"]];
    [self.navigationController.navigationBar setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"nav_back_icon"]];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    backItem.tintColor = RGB(0, 0, 0);
    self.navigationItem.backBarButtonItem = backItem;
}

#pragma mark - 设置导航栏
- (void)setNavWithTitle:(NSString *)title isShowBack:(BOOL)isShowBack{
    if (isShowBack) {
        UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"nav_back_icon"] style:UIBarButtonItemStylePlain target:self action:@selector(clickLeftBtn:)];
        backItem.tintColor = kWhiteColor;
        self.navigationItem.leftBarButtonItem = backItem;
    } else {
        self.navigationItem.leftBarButtonItem = nil;
    }
    self.navigationItem.title = title;
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : RGB(0, 0, 0),
    NSFontAttributeName : FONT(18)}];
}


#pragma mark - 导航栏点击方法
- (void)clickLeftBtn:(UIButton *)leftBtn {
    if (self.navigationController.viewControllers.count == 1)
    {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    else
    {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (void)dealloc {
    NSLog(@"%s------%@", __func__, [self class]);
}

@end
